package Units;
import info.gridworld.grid.Location;


public class ARTILLERY extends Light_Vehicle{
	public ARTILLERY(){
		super(null, new Cannon(75), .6, 1.2, 6000, 5);
	}
	
	public String Description(){
		return "The Artillery unit is vital to an effective defense./n" +
				"It has a powerful ranged attack of 2-3 tiles but no close/n" +
				"quarters capabilities. This unit provides valuable support.";
	}
	
	public String toString(){
		return "an Artillery unit with " + getHealth() + " health";
	}
	
	public boolean isValidAttack(Location loc){
		if (loc.equals(getLocation().getAdjacentLocation(0).getAdjacentLocation(0))){
			return true;
		}else if (loc.equals(getLocation().getAdjacentLocation(90).getAdjacentLocation(90))){
			return true;
		}else if (loc.equals(getLocation().getAdjacentLocation(180).getAdjacentLocation(180))){
			return true;
		}else if (loc.equals(getLocation().getAdjacentLocation(270).getAdjacentLocation(270))){
			return true;
		}else if (loc.equals(getLocation().getAdjacentLocation(0).getAdjacentLocation(0).getAdjacentLocation(0))){
			return true;
		}else if (loc.equals(getLocation().getAdjacentLocation(90).getAdjacentLocation(90).getAdjacentLocation(90))){
			return true;
		}else if (loc.equals(getLocation().getAdjacentLocation(180).getAdjacentLocation(180).getAdjacentLocation(180))){
			return true;
		}else if (loc.equals(getLocation().getAdjacentLocation(270).getAdjacentLocation(270).getAdjacentLocation(270))){
			return true;
		}else
			return false;
	}
	
	
	/**
	 * this method overrides the main attack to prevent retaliation (it is a ranged unit after all)
	 */
	public void Attack(Location loc){
		Unit a = (Unit) getGrid().get(loc);
		if(isValidAttack(loc))
			a.setHealth(a.getHealth()- getDamage(super.getWeapon2(), a));
		else
			System.out.print("Attacks must be 2-3 tiles away for artillery");
		if(a.getHealth() < 1){
			a.removeSelfFromGrid(); // kills the unit if it has 0 health

	}
}
}
